package com.woniuxy.bookmall.service;

import com.woniuxy.bookmall.entity.TBanner;
import com.woniuxy.bookmall.mapper.TBannerMapper;
import com.woniuxy.bookmall.utils.RedisUtils;
import io.lettuce.core.RedisURI;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BannerService {
    @Autowired
    TBannerMapper bannerMapper ;

    @Autowired
    RedisUtils redisUtils ;

    public List<TBanner> findAll(){
        List<TBanner>  lists = (List<TBanner>) redisUtils.get("WONIU_BANNER");
        if (lists != null) {
            return lists ;
        }else {
            synchronized (BannerService.class){
                lists = (List<TBanner>)redisUtils.get("WONIU_BANNER");
                if (lists != null) {
                    return lists ;
                }else {
                    //查询数据库
                    lists = bannerMapper.selectAll();
                    redisUtils.set("WONIU_BANNER",lists,60*60);
                    return lists ;
                }
            }
        }
    }
}
